package com.service.impl;

import com.dao.CustomerDao;
import com.pojo.Customer;
import com.service.CustomerService;
import com.util.BaseDao;
import org.apache.ibatis.session.SqlSession;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;

import java.util.List;

public class CustomerServiceImpl extends BaseDao implements CustomerService {
    CustomerDao dao;
    SqlSession session1;
    List<Customer> list;
    Customer customer;

    @Override
    public List<Customer> query() {
        session1=getSession();
        dao=getSession().getMapper(CustomerDao.class);
        list= dao.query();
        closeSession(session1);
        return list;
    }

    @Override
    public void add(Customer customer) {
        session1=getSession();
        dao=getSession().getMapper(CustomerDao.class);
        dao.add(customer);
        closeSession(session1);
    }

    @Override
    public void del(Integer id) {
        session1=getSession();
        dao=getSession().getMapper(CustomerDao.class);
        dao.del(id);
        closeSession(session1);
    }

    @Override
    public void update(Customer customer) {
        session1=getSession();
        dao=getSession().getMapper(CustomerDao.class);
        dao.update(customer);
        closeSession(session1);
    }

    @Override
    public Customer queryById(Integer id) {
        session1=getSession();
        dao=getSession().getMapper(CustomerDao.class);
        customer= dao.queryById(id);
        closeSession(session1);
        return customer;
    }
}
